package Projectiles;

import java.awt.Graphics;

import FrameWork.Entity;
import Main.SpaceGame;
import MiscelaneousEntities.Explosion;
import World.TileType;
import World.World;

public abstract class Projectile
{
	public double x,y;
	double xVel,yVel;
	private SpaceGame main;
	public int blastRadius;
	int explodeCnt = 0;
	public boolean friendly;
	
	public Projectile(double x, double y, double xVel, double yVel, SpaceGame main, boolean friendly)
	{
		this.x = x;
		this.y = y;
		this.xVel = xVel;
		this.yVel = yVel;
		this.main = main;
		blastRadius = 2;
		explodeCnt = 0;
		this.friendly = friendly;
	}
	
	public Projectile(double x, double y, double xVel, double yVel, SpaceGame main, boolean friendly, int explodeCnt)
	{
		this.x = x;
		this.y = y;
		this.xVel = xVel;
		this.yVel = yVel;
		this.main = main;
		blastRadius = 2;
		this.explodeCnt = explodeCnt;
		this.friendly = friendly;
	}

	public abstract void draw(Graphics g);
	
	public void update()
	{
		if(explodeCnt < 3)
			explodeCnt++;
		y+=yVel;
		x+=xVel;
		if(x<0 || x>=World.worldXSize*10 || y<0 || y>=World.worldYSize*10)
			main.projectileManager.projectileList.remove(this);
		if((int)(x/10+.5) >= 0 && (int)(x/10+.5) < World.worldXSize-1 && (int)(y/10+.5) >= 0 && (int)(y/10+.5) < World.worldYSize-1)
		{
			if(main.world.tiles[(int)(x/10+.5)][(int)(y/10+.5)].isSolid() || main.world.tiles[(int)(x/10+.5)+1][(int)(y/10+.5)].isSolid() || main.world.tiles[(int)(x/10+.5)][(int)(y/10+.5)+1].isSolid() || main.world.tiles[(int)(x/10+.5)+1][(int)(y/10+.5)+1].isSolid())
			{
				if(explodeCnt >= 3)
				{
					main.miscManager.miscList.add(new Explosion((int)(x/10+.5), (int)(y/10+.5), blastRadius, main));
					main.projectileManager.projectileList.remove(this);
				}
			}
		}
	}
}
